package com.meterreadingsys.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * SQLite帮助类，建表及更新表，打开数据库
 * 
 * @author king
 * 
 */
public class DBOpenHelper extends SQLiteOpenHelper {

	public DBOpenHelper(Context context) {
		super(context, "water.db", null, 2);
	}

	/**
	 * 建表
	 */
	@Override
	public void onCreate(SQLiteDatabase db) {
		String sql = "CREATE TABLE userinfo (_id  INTEGER PRIMARY KEY AUTOINCREMENT,usernumber varchar(20), username varchar(100), userpass varchar(10),useradds valchar(10)"
				+ " ,phone valchar(20))";
		System.out.println(sql+"用户信息");
		String sql1="create table testfrom (_id  INTEGER PRIMARY KEY AUTOINCREMENT,userid varchar(20),_name varchar2(100),num varchar(20),money varchar(20)) ";
		System.out.println(sql1+"测试");
		db.execSQL(sql1);
		db.execSQL(sql);

	}

	/**
	 * 当前版本号高于上次创建或升级的版本号，SQLiteOpenHelper会调用onUpdate()方法
	 */
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS userinfo");
		db.execSQL("drop table if exists testfrom");
		onCreate(db);

	}

}
